package com.edu.exam.enums.grading;

/**
 * 缓存驱逐策略枚举
 */
public enum CacheEvictionPolicy {
    SIZE_BASED("SIZE_BASED", "基于大小驱逐"),
    TIME_BASED("TIME_BASED", "基于时间驱逐"),
    FREQUENCY_BASED("FREQUENCY_BASED", "基于频率驱逐"),
    PRIORITY_BASED("PRIORITY_BASED", "基于优先级驱逐"),
    MEMORY_PRESSURE("MEMORY_PRESSURE", "基于内存压力驱逐"),
    MANUAL_CLEANUP("MANUAL_CLEANUP", "手动清理驱逐");

    private final String code;
    private final String description;

    CacheEvictionPolicy(String code, String description) {
        this.code = code;
        this.description = description;
    }

    public String getCode() {
        return code;
    }

    public String getDescription() {
        return description;
    }

    public static CacheEvictionPolicy fromCode(String code) {
        for (CacheEvictionPolicy policy : values()) {
            if (policy.getCode().equals(code)) {
                return policy;
            }
        }
        throw new IllegalArgumentException("Unknown cache eviction policy code: " + code);
    }

    @Override
    public String toString() {
        return description;
    }
}